//
//  SpriteEntity.cpp
//  GSEngine
//
//  Created by Александр on 02.02.14.
//  Copyright (c) 2014 SNK. All rights reserved.
//

#include "SpriteEntity.h"
#include "EntityManager.h"
#include <GSEngine/Main/GSApplication.h>

namespace GSEngine
{
    SpriteEntity::SpriteEntity()
    {
        setType(ESpriteEntity);
        int verCount = 4;
        setVertexCount(verCount);
        float vertexCoords[12] =  {-1.0f,  1.0, 0.0f,
                                   -1.0f, -1.0, 0.0f,
                                    1.0f, -1.0, 0.0f,
                                    1.0f,  1.0, 0.0f};
        setVertexCoords(vertexCoords, verCount);
        float texCoords[12] = {0.0f, 1.0f,
                               0.0f, 0.0f,
                               1.0f, 0.0f,
                               1.0f, 1.0f};
        setTextureCoords(texCoords, verCount);
        m_texture = new GSTexture();
    }
    SpriteEntity::~SpriteEntity()
    {
        delete m_texture;
    }
    GSTexture* SpriteEntity::getSpriteTexture()
    {
        return m_texture;
    }
    SpriteEntity* CreateSpriteEntity(const char* path)
    {
        SpriteEntity* sprite = new SpriteEntity();
        std::string absPath = GSEngine::GSApplication::getInstance()->getPlatform()->getResourcesPath() + "/" + path;
//        GSApplication::getInstance()->getPlatform()->getPa
        sprite->getSpriteTexture()->loadTexture(absPath.c_str(), "rb");
        sprite->setTexture(sprite->getSpriteTexture());
        EntityManager::getInstance()->addObject(sprite);
        return sprite;
    }
}
